public class Solution {
    public class TreeNode {
        TreeNode left = null;
        TreeNode right = null;
        int val = 0;

        public TreeNode(int val) {
            this.val = val;
        }
    }

    //输入一棵节点数为 n 二叉树，判断该二叉树是否是平衡二叉树。
    //在这里，我们只需要考虑其平衡性，不需要考虑其是不是排序二叉树
    public boolean IsBalanced_Solution(TreeNode pRoot) {
        if (pRoot == null) {
            return true;
        }
        int leftHeight = getHeight(pRoot.left);
        int rightHeight = getHeight(pRoot.right);
        return Math.abs(leftHeight - rightHeight) <= 1 && IsBalanced_Solution(pRoot.left) && IsBalanced_Solution(pRoot.right);
    }
    public int getHeight(TreeNode pRoot) {
        if (pRoot == null) {
            return 0;
        }
        return 1 + Math.max(getHeight(pRoot.left), getHeight(pRoot.right));
    }
}



